import io
from datetime import datetime
import shutil
class RunTime:
    def __enter__(self):
        self.start_time=datetime.now()
        print(self.start_time)
        return self.start_time
    def __exit__(self, exc_type, exc_val, exc_tb):
        self.end_time=datetime.now()
        print(self.end_time)
        print('程序运行的时间为%s'%(self.start_time-self.end_time))

# run=RunTime()

with RunTime() as a:
    sio=io.StringIO()
    sio.write('今天天气不错')
    print(sio.getvalue())
    sio.close()
    print('你好')